﻿using System.Diagnostics;
using System.Management;

namespace boda.utilities.Systems
{
    public static class HardwareInfos
    {
        /// <summary>
        /// 获取设备硬件信息
        /// </summary>
        public static string GetHostHardwareInfos()
        {
            // 创建ManagementObjectSearcher对象
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Processor");
            var infos = searcher.Get();
            string hardwareInfo=string.Empty;
            // 遍历查询结果集
            foreach (ManagementObject obj in infos)
            {
                Debug.WriteLine("-----------------------------------");
                Debug.WriteLine("Win32_Processor instance");
                Debug.WriteLine("-----------------------------------");
                Debug.WriteLine("Architecture: {0}", obj["Architecture"]);
                Debug.WriteLine("Caption: {0}", obj["Caption"]);
                Debug.WriteLine("Family: {0}", obj["Family"]);
                Debug.WriteLine("ProcessorId: {0}", obj["ProcessorId"]);
                hardwareInfo = $"{obj["ProcessorId"]}";
                //hardwareInfo += $"{obj["ProcessorId"]}-{obj["Architecture"]}-{obj["Family"]}-{obj["Architecture"]}";
            }
            Debug.WriteLine($"hardwareInfo:{hardwareInfo}");
            return hardwareInfo;
        }

    }
}
